package datamodels

import (
	validation "github.com/go-ozzo/ozzo-validation/v4"
)

type User struct {
	ID int64 `json:"id" userForm:"id" sql:"id"`
	NickName string `json:"nickName" userForm:"nickName" sql:"nickname"`
	UserName string `json:"userName" userForm:"userName" sql:"username"`
	HashPassword string `json:"password" userForm:"password" sql:"password"`
	AuthToken string `json:"authToken" userForm:"authToken" sql:"auth_token"`//登录凭证
	CreateAt string `json:"createAt" userForm:"createAt" sql:"create_at"`
	UpdateAt string `json:"updateAt" userForm:"updateAt" sql:"update_at"`
	ExpireAt string `json:"expireAt" userForm:"expireAt" sql:"expire_at"`//过期时间
}

func (user User) RegisterValidate() error  {
	return validation.ValidateStruct(&user,
		validation.Field(&user.NickName, validation.Required.Error("不能为空"), validation.Length(5, 20).Error("字符要在5-20之间")),
		validation.Field(&user.UserName, validation.Required.Error("不能为空"), validation.Length(5, 20).Error("字符要在5-20之间")),
		validation.Field(&user.HashPassword, validation.Required.Error("不能为空"), validation.Length(5, 20).Error("字符要在5-20之间")),
	)
}

